package com.yidu.t299.dao.ssk;

import com.yidu.t299.domain.ssk.School;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SchoolsMapper {
    /**
     * 根据校区编号删除该校区信息
     * @param schoolId 校区编号
     * @return 影响的行数(返回1则为成功)
     */
    @Delete({
        "delete from school" +
        " where school_id = #{schoolId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer schoolId);

    /**
     * 添加校区信息
     * @param record 校区对象
     * @return 影响的行数(返回1则为成功)
     */
    @Insert({
        "insert into school (school_id, school_name)" +
        " values (#{schoolId,jdbcType=INTEGER}, #{schoolName,jdbcType=VARCHAR})"
    })
    int insert(School record);

    /**
     * 根据校区编号查询指定的信息
     * @param schoolId 校区编号
     * @return 校区对象
     */
    @Select({
        "select" +
        " school_id, school_name" +
        " from school" +
        " where school_id = #{schoolId,jdbcType=INTEGER}"
    })
    @Results(id = "SchoolMap",value = {
            @Result(id = true,column = "school_id",property = "schoolId"),
            @Result(column = "school_name",property = "schoolName")
    })
    School selectByPrimaryKey(Integer schoolId);

    /**
     * 按条件分页查询校区数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 校区对象集合
     */
    @Select("select * from school where 1=1 ${condition} limit #{page},#{rows}")
    @ResultMap("SchoolMap")
    List<School> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询school表中数据行数
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("select count(*) from school where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);

    /**
     * 根据校区信息修改其数据
     * @param record 校区对象
     * @return 影响的行数(返回1则为成功)
     */
    @Update({
        "update school",
        " set school_name = #{schoolName,jdbcType=VARCHAR}",
        " where school_id = #{schoolId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(School record);
}